<?php
session_start();
define('INDEX',true);
require("../../_config/config.php");
require("../../_config/db_connection.php");
require("../../common/functions_mysql.php");
require("../../common/functions_common.php");
require("../../common/init.php"); // Initial file
require("../../common/lang_".$cfg['admin_language'].".php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php echo $cfg['admin_header']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $cfg['default_charset']; ?>">
<script language="javascript" src="chart.js"></script>
<style>
BODY
{
	background-color:#FFFFFF;
	margin: 0px 0px 0px 0px;
	font-family: Tahoma, Arial;
	font-size:11px;
}
TD { font-size:11px; font-family: Tahoma, Arial;}
DIV { font-size:11px; font-family: Tahoma, Arial;}
</style>
</head>
<body>
<?php
$year_visitor = $DB->fetch_array($DB->query('SELECT SUM(visitors) AS total_visitors FROM '.$tbl["visitor"].' WHERE year="'.@$_GET['year'].'"'));
$year_visitors = $year_visitor['total_visitors'];

// Get visitors per month
for($x=1;$x<=12;$x++)
{
		$visitor_months = $DB->fetch_array($DB->query('SELECT SUM(visitors) AS total_visitors FROM '.$tbl["visitor"].' WHERE year="'.@$_GET['year'].'" AND month="'.$x.'"'));
		$visitor_month[$x] = $visitor_months['total_visitors'];
}
## LOAD CHART VISIT PER MONTH
// Delete old xml
//unlink('xml/visit_per_month.xml');
// Create new xml
$xml_vpm = "<?xml version='1.0' encoding='UTF-8' ?>";
$xml_vpm .= "<graph caption='".$_GET['year'].": ".$year_visitors." visitors' chartLeftMargin='5' chartRightMargin='5'  chartTopMargin='0' numdivlines='5' lineThickness='3' showValues='0'  numVDivLines='10' formatNumberScale='0' rotateNames='0' decimalPrecision='0' anchorRadius='2' anchorBgAlpha='1' numberPrefix='' divLineAlpha='100' showAlternateHGridColor='1' yAxisMinValue='800000' shadowAlpha='50' ><categories >";
for($y=1;$y<=12;$y++) 
{
	$xml_vpm .= "<category Name='".$lang_month_short[$y]."' />";
}
$xml_vpm .= "</categories>";
$xml_vpm .= "<dataset seriesName='Unique visitors' color='#CC0000' anchorBorderColor='000000' anchorRadius='5'>";
for($x=1;$x<=12;$x++) 
{
	$xml_vpm .= "<set value='".(($visitor_month[$x])?$visitor_month[$x]:0)."' />";
}
$xml_vpm .= "</dataset></graph>";
$vpm_file_url = "xml/visit_per_month.xml";
$fp = fopen($vpm_file_url,'w');
$write = fwrite($fp,$xml_vpm);

if($year_visitors)
{
echo '<div id="visit_per_month" align="center">
		Your browser is not installed Flash Player. Please install flash player to view.
	</div>
	<script type="text/javascript">
		var chart_month = new JcasChart("swf/line.swf", "cm", "600", "300");
		chart_month.setDataURL("xml/visit_per_month.xml?SID='.session_id().'&rand='.rand(111111,99999).'");
		chart_month.render("visit_per_month");
	</script>';
}
else
	echo '<br/><div align=center>'.message(sprintf($lang['no_year_data'],get('year')),'info').'</center>';
?>

</body>
</html>
<?php
$DB->close;
ob_end_flush();
?>